WT_DECLARE_WT_MEMBER(1,JavaScriptConstructor,"WFileDropWidget",function(m,d,l){jQuery.data(d,"lobj",this);var f=this,j="Wt-filedropzone-hover",c=[],k=false,i=true;this.eventContainsFile=function(a){var b=a.dataTransfer.types!=null&&a.dataTransfer.types.length>0&&a.dataTransfer.types[0]=="Files";return a.dataTransfer.items!=null&&a.dataTransfer.items.length>0&&a.dataTransfer.items[0].kind=="file"||b};this.validFileCheck=function(a,b,g){var e=new FileReader;e.onload=function(){b(true,g)};e.onerror=
function(){b(false,g)};e.readAsText(a)};d.setAcceptDrops=function(a){i=a};d.ondragenter=function(a){i&&f.eventContainsFile(a)&&f.setHoverStyle(true)};d.ondragleave=function(){i&&f.setHoverStyle(false)};d.ondragover=function(a){a.preventDefault()};d.ondrop=function(a){a.preventDefault();if(i){f.setHoverStyle(false);if(!(window.FormData===undefined||a.dataTransfer.files==null||a.dataTransfer.files.length==0)){Math.floor(Math.random()*32768);for(var b=[],g=0;g<a.dataTransfer.files.length;g++){var e=
new XMLHttpRequest;e.id=Math.floor(Math.random()*Math.pow(2,31));e.file=a.dataTransfer.files[g];c.push(e);var h={};h.id=e.id;h.filename=e.file.name;h.type=e.file.type;h.size=e.file.size;b.push(h)}console.log(b);Wt.emit(d,"dropsignal",JSON.stringify(b))}}};d.markForSending=function(a){for(var b=0;b<a.length;b++)for(var g=a[b].id,e=0;e<c.length;e++)if(c[e].id==g){c[e].ready=true;break}k||c[0].ready&&f.requestSend()};this.requestSend=function(){if(c[0].skip)f.uploadFinished(null);else{k=true;Wt.emit(d,
"requestsend",c[0].id)}};d.send=function(a){console.log("sending file");xhr=c[0];if(xhr.file.size>l){Wt.emit(d,"filetoolarge",xhr.file.size);f.uploadFinished(null)}else f.validFileCheck(xhr.file,f.actualSend,a)};this.actualSend=function(a,b){if(a){xhr=c[0];xhr.addEventListener("load",f.uploadFinished);xhr.addEventListener("error",f.uploadFinished);xhr.addEventListener("abort",f.uploadFinished);xhr.addEventListener("timeout",f.uploadFinished);xhr.open("POST",b);a=new FormData;a.append("file-id",xhr.id);
a.append("data",xhr.file);xhr.send(a)}else f.uploadFinished(null)};this.uploadFinished=function(a){console.log("finished sending (type = "+a+")");a!=null&&a.type=="load"&&a.currentTarget.status==200&&Wt.emit(d,"uploadfinished",c[0].id);c.splice(0,1);if(c[0]&&c[0].ready)f.requestSend();else{k=false;Wt.emit(d,"donesending")}};d.cancelUpload=function(a){if(c[0].id==a)c[0].abort();else for(var b=1;b<c.length;b++)if(c[b].id==a)c[b].skip=true};this.setHoverStyle=function(a){a?$(d).addClass(j):$(d).removeClass(j)};
d.configureHoverClass=function(a){j=a}});
